﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PRET.ReportControlLib.Controls
{
    public partial class EmployeAttendanceFilter : UserControl
    {
        private readonly static string[] Months = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" };
        private readonly static string[] Teams = { "A班", "B班", "C班", "D班", "E班", "F班", "机修班", "颜色班", "辅助班" };
        public event ShowAttendanceReportViewEventHandle showReportEvent;
        public event ShowAttendanceReportViewWithTeamNameEventHandle showReportByTeamEvent;

        public EmployeAttendanceFilter()
        {
            InitializeComponent();
            InitializeYearsMonths();
        }
        private void InitializeYearsMonths()
        {
            this.dateTimePicker.MaxDate = DateTime.Today;
            this.dateTimePicker.Value = DateTime.Today;
            // 初始化班组
            this.teamComboBox.DataSource = Teams;
        }

        public void EnableControls(bool sign)
        {
            this.dateTimePicker.Enabled = sign;
            this.teamComboBox.Enabled = sign;
            this.reportViewBtn.Enabled = sign;
        }

        public DateTime GetSelectedYearMonth
        {
            get
            {
                string yearmonth = this.dateTimePicker.Value.ToString("yyyy-MM");
                return DateTime.Parse(yearmonth);
            }
        }

        public string GetSelectedTeam
        {
            get { return this.teamComboBox.SelectedItem.ToString(); }
        }

        private void reportViewBtn_Click(object sender, EventArgs e)
        {
            if (showReportEvent != null)
            {
                ShowAttendanceReportViewEventArgs eventArg = new ShowAttendanceReportViewEventArgs();
                eventArg.Month = this.GetSelectedYearMonth;
                eventArg.Team = this.GetSelectedTeam;
                showReportEvent(this, eventArg);
            }
        }

        private void teamComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (showReportByTeamEvent != null)
            {
                ShowAttendanceReportViewTeamNameEventArgs eventArg = new ShowAttendanceReportViewTeamNameEventArgs();
                eventArg.Team = this.GetSelectedTeam;
                showReportByTeamEvent(this, eventArg);
            }
        }
    }

    public delegate void ShowAttendanceReportViewEventHandle(object sender, ShowAttendanceReportViewEventArgs args);
    public delegate void ShowAttendanceReportViewWithTeamNameEventHandle(object sender, ShowAttendanceReportViewTeamNameEventArgs args);

    public class ShowAttendanceReportViewEventArgs : EventArgs
    {
        public ShowAttendanceReportViewEventArgs()
        { }
        private DateTime month;

        public DateTime Month
        {
            get { return month; }
            set { month = value; }
        }

        private string team;

        public string Team
        {
            get { return team; }
            set { team = value; }
        }
    }

    public class ShowAttendanceReportViewTeamNameEventArgs : EventArgs
    {
        public ShowAttendanceReportViewTeamNameEventArgs()
        { }

        private string team;

        public string Team
        {
            get { return team; }
            set { team = value; }
        }
    }
}
